<?php
/**
 * Created by PhpStorm.
 * User: g
 * Date: 2017/4/27
 * Time: 17:02
 */

namespace app\front\controller;


use think\Request;

class Feedback extends Home
{
    public function index(){
        $user  = $this->user->where("id",$this->userId)->find();
        $records = db("feedback")->where("username",$user['username'])->paginate(15);
        $this->assign("records",$records);
        return $this->fetch();
    }
    public function add(){
        if(IS_POST){
            $post = input();
            $user = $this->user->where("id",$this->userId)->find();
            $post['username'] = $user['username'];
            $post['email'] = $user['email'];
            $post['createdate'] = date('Y-m-d H:i:s');
            $post['ip'] = Request::instance()->ip();
            $res = db("feedback")->insert($post);
            if($res){
                return  $this->ret->setCode(0)->setMsg("反馈成功，请等待回复")->toJson();
            }else{
                return $this->ret->setCode(1)->setMsg("返回失败，请重试")->toJson();
            }
        }else{
            return $this->fetch();
        }
    }
} 
